//
//  ChangelogpassViewController.m
//  Vpay
//
//  Created by 伟大大 on 2018/9/27.
//  Copyright © 2018年 丁伟佳. All rights reserved.
//

#import "ChangelogpassViewController.h"
#import "UILabel+StringFrame.h"
#import "LoginViewController.h"
@interface ChangelogpassViewController () {
    CGSize titleSize;
    CGSize titleSize1;

}

@end

@implementation ChangelogpassViewController

#pragma mark -
#pragma mark - for lifeCircle
#pragma mark -
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    //    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    //    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if ([self.xgType isEqualToString:@"xgzf"]) {
        self.title = @"修改支付密码";

    }else {
        self.title = @"修改登录密码";

    }
//    self.title = @"修改登录密码";
    self.view = [[[NSBundle mainBundle]loadNibNamed:@"ChangelogpassViewController" owner:self options:nil]lastObject];
    self.view.backgroundColor = BACKCOLOR;
    
    
    
//    [self initData];
    [self initNavBtns];
    [self initViews];
    
    //    [NSThread detachNewThreadSelector:@selector(requestData) toTarget:self withObject:nil];
    
    //    [NSThread detachNewThreadSelector:@selector(requestDingdanData) toTarget:self withObject:nil];
}
#pragma mark -
#pragma mark - for Views
#pragma mark -

- (void)initNavBtns {
    
    self.navigationItem.leftBarButtonItem = [AppUtility getNavBtnItemLefBacktWith:@selector(leftNavBtnClicked) andTarget:self];
}
- (void)initViews {
    
    
    if ([self.xgType isEqualToString:@"xgzf"]) {
        self.oldpass_label.text = @"旧支付密码";
        self.oldpass_textfiled.placeholder = @"请输入您现在的支付密码";
        self.newpass_label.text = @"新支付密码";
        self.newpass_textfiled.placeholder = @"请输入要设置的新支付密码";
        
        [self.forget_btn setTitle:@"忘记支付密码？" forState:UIControlStateNormal];
        
        self.forget_btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        
    }else {
        
        self.oldpass_label.text = NSLocalizedString(@"oldpass", nil);
        self.oldpass_textfiled.placeholder = NSLocalizedString(@"enterold", nil);
        self.newpass_label.text = NSLocalizedString(@"newpass", nil);
        self.newpass_textfiled.placeholder = NSLocalizedString(@"enternew", nil);
        
        [self.forget_btn setTitle:NSLocalizedString(@"forgetlogpass", nil) forState:UIControlStateNormal];
        
        self.forget_btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        
    }
//    self.oldpass_label.text = NSLocalizedString(@"oldpass", nil);
//    self.oldpass_textfiled.placeholder = NSLocalizedString(@"enterold", nil);
//    self.newpass_label.text = NSLocalizedString(@"newpass", nil);
//    self.newpass_textfiled.placeholder = NSLocalizedString(@"enternew", nil);
//    
//    [self.forget_btn setTitle:NSLocalizedString(@"forgetlogpass", nil) forState:UIControlStateNormal];
//
//    self.forget_btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.Confirm_btn setTitle:NSLocalizedString(@"fconfirm", nil) forState:UIControlStateNormal];
    self.Confirm_btn.layer.cornerRadius = 4.5;
    
    titleSize = [self.oldpass_label boundingRectWithSize:CGSizeMake(0, self.oldpass_label.frame.size.height)];
    self.oldpass_label.frame = CGRectMake(self.oldpass_label.frame.origin.x, self.oldpass_label.frame.origin.y+1, titleSize.width, self.oldpass_label.frame.size.height);
    self.oldpass_textfiled.frame = CGRectMake(self.oldpass_label.frame.origin.x+titleSize.width+44*theApp.autoSizeScaleX, self.oldpass_textfiled.frame.origin.y, self.oldpass_textfiled.frame.size.width, self.oldpass_textfiled.frame.size.height);
    
    titleSize1 = [self.newpass_label boundingRectWithSize:CGSizeMake(0, self.newpass_label.frame.size.height)];
    self.newpass_label.frame = CGRectMake(self.newpass_label.frame.origin.x, self.newpass_label.frame.origin.y, titleSize1.width, self.newpass_label.frame.size.height);
    self.newpass_textfiled.frame = CGRectMake(self.newpass_label.frame.origin.x+titleSize1.width+44*theApp.autoSizeScaleX, self.newpass_textfiled.frame.origin.y, self.newpass_textfiled.frame.size.width, self.newpass_textfiled.frame.size.height);
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapAction)];
    [self.view addGestureRecognizer:tap];
}
#pragma mark -
#pragma mark for evevts
#pragma mark -
- (void)leftNavBtnClicked {
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)TapAction {
    
    if ([_oldpass_textfiled isFirstResponder]) {
        [_oldpass_textfiled resignFirstResponder];
    }
    if ([_newpass_textfiled isFirstResponder]) {
        [_newpass_textfiled resignFirstResponder];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_oldpass_label release];
    [_oldpass_textfiled release];
    [_newpass_label release];
    [_newpass_textfiled release];
    [_forget_btn release];
    [_Confirm_btn release];
    [super dealloc];
}
- (IBAction)forget_btnClik:(UIButton *)sender {
}
- (IBAction)Confirm_btnClik:(UIButton *)sender {
//    - (void)makeToast:(NSString *)message duration:(CGFloat)interval  position:(id)position title:(NSString *)title image:(UIImage *)image {

    if ([AppUtility isBlankString:_oldpass_textfiled.text]) {
//        [self.view makeToast:NSLocalizedString(@"oldpasskong", nil)];

        [self.view makeToast:NSLocalizedString(@"oldpasskong", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];
        return;
    }
    if ([AppUtility isBlankString:_newpass_textfiled.text]) {
//        [self.view makeToast:NSLocalizedString(@"newpasskong", nil)];
        [self.view makeToast:NSLocalizedString(@"newpasskong", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];

        return;
    }
    if ([_oldpass_textfiled.text length]<6) {

//        [self.view makeToast:NSLocalizedString(@"oldpassts", nil)];
        [self.view makeToast:NSLocalizedString(@"oldpassts", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];

        return;

    }
    if ([_newpass_textfiled.text length]<6) {

//        [self.view makeToast:NSLocalizedString(@"newpassts", nil)];
        [self.view makeToast:NSLocalizedString(@"newpassts", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];

        return;

    }
    if (![AppUtility judgePassWordLegal:_oldpass_textfiled.text]) {
//        [self.view makeToast:NSLocalizedString(@"oldpassts", nil)];
        [self.view makeToast:NSLocalizedString(@"oldpassts", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];

        return;
    }
    if (![AppUtility judgePassWordLegal:_newpass_textfiled.text]) {
//        [self.view makeToast:NSLocalizedString(@"newpassts", nil)];
        [self.view makeToast:NSLocalizedString(@"newpassts", nil) duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];

        return;
    }
    
    NSString *postStr = @"";
    
    postStr = [NSString stringWithFormat:@"userid=%@&pwd=%@&pwdrpt=%@&pwdtype=1",@"",_oldpass_textfiled.text,_newpass_textfiled.text];
    
    NSDictionary *resultDict =[NetUtility getDataWithURLStr:KURLXiuGaiMiMa andPostStr:postStr andView:self.navigationController.view];
    
    UEXNSLog(@"kURL==%@%@ resultDict=%@",KURLXiuGaiMiMa,postStr,resultDict);
    
    if (resultDict) {
        int stauts = [[resultDict objectForKey:@"s"] intValue];
        
        if (stauts==1) {
            
            //            NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary: [AccountController getAccountInfo]];
            //
            //            [dic setObject:textField.text forKey:@"nickname"];
            //            [AccountController setAccountInfo:dic];
            
            [self.navigationController popViewControllerAnimated:YES];
            [self.navigationController.view makeToast:[resultDict objectForKey:@"i"]];

        }else if (stauts == 303) {
            
            LoginViewController *vc = [[LoginViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
        
        //        [self.navigationController.view makeToast:[resultDict objectForKey:@"datas"][@"message"]];
    }
}
@end
